package com.lechuang.user.controller;

import cn.hutool.json.JSONUtil;
import com.lechuang.common.result.Result;
import com.lechuang.user.dto.SaveUserConsigneeDto;
import com.lechuang.user.dto.UserConsigneeRequestDto;
import com.lechuang.user.entity.UserConsignee;
import com.lechuang.user.manager.UserConsigneeManager;
import com.lechuang.user.vo.UserConsigneeVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/userConsignee")
@Log4j2
@Tag(name = "用户收货地址")
public class UserConsigneeController {

    @Resource
    private UserConsigneeManager userConsigneeManager;

    @Operation(summary = "修改用户收货地址")
    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(@Valid @RequestBody SaveUserConsigneeDto saveUserConsigneeDto){
        log.info("修改用户收货地址------{}", JSONUtil.toJsonStr(saveUserConsigneeDto));
        userConsigneeManager.saveOrUpdate(saveUserConsigneeDto);
        return Result.success();
    }

    @Operation(summary = "查询用户收货地址")
    @PostMapping("/getConsigneeVoList")
    public Result getConsigneeList(@Valid @RequestBody UserConsigneeRequestDto userConsigneeRequestDto){
        log.info("修改用户收货地址------{}", JSONUtil.toJsonStr(userConsigneeRequestDto));
        List<UserConsigneeVo> userConsigneeVos = userConsigneeManager.getConsigneeList(userConsigneeRequestDto);
        return Result.success(userConsigneeVos);
    }

    @Operation(summary = "删除用户收货地址")
    @GetMapping("/removeById")
    public Result removeById(@RequestParam Long id){
        userConsigneeManager.removeById(id);
        return Result.success();
    }


}
